package com.neuedu.corejava.ch12Test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

class FileCopy {

	public static void main(String[] args) {
		try {
			Path directory = Paths.get("d:/io");
			if (!Files.exists(directory)) {
				Files.createDirectory(directory);
				System.out.println("创建目录成功");
			} 
			
			Path file = Paths.get("d:/io/copysrc.doc");
			if (!Files.exists(file)) {
				 Files.createFile(file);
				System.out.println("创建文件成功");
			} 
			Path fiPath = Paths.get("d:/io/copydes.doc");
			
			if(Files.exists(fiPath)) {
				Files.delete(fiPath);
				
			}else {
				Files.createFile(fiPath);
			}
			Files.copy(file, fiPath);
			System.out.println("拷贝成功");
			
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
}
